|
|
|
|
|
|
|
Puzzle 9
Translating DEVMODE |
|
|
|
|
|
|
|
|
One of the things Windows does for programmers is make it possible to write code that has little dependency on the underlying system devices. It wasn't too many years ago that any programmer who wanted his application to print would have to create and distribute his own drivers for every printer he wanted to support. Currently, Windows hides the details of devices so well that most Visual Basic programmers need pay little attention to the type of printer or display their program will use. |
|
|
|
|
|
|
|
|
But the Windows API does include many functions that allow programmers to not only find out about underlying devices, but also to configure them. For example, you've probably used the Control Panel applet to change the settings of your display card and select a new resolution or color depth. But you may not be aware that it's actually quite easy to perform this operation from any program using the ChangeDisplaySettings API. |
|
|
|
|
|
|
|
|
This API function takes as a parameter a structure named DEVMODE. The DEVMODE structure is a sort of multipurpose structure used to describe many types of devices under Windows, particularly printers and display devices. |
|
|
|
|
|
|
|
|
The EnumDisplaySettings function allows you to easily obtain the DEVMODE structure for every display setting your graphic card supports and is the subject of this puzzle. |
|
|
|
|
|
|
|
|
The DEVMODE structure is declared in C as follows: |
|
|
|
|
|
|
|
|
/* size of a device name string */
#define CCHDEVICENAME 32
/* size of a form name string */
#define CCHFORMNAME 32
typedef struct _devicemodeA {
BYTE dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
short dmOrientation;
short dmPaperSize; |
|
|
|
|
|